package com.cqc.progressdialog02;

import android.app.ProgressDialog;
import android.support.annotation.IntDef;
import android.support.v4.app.NavUtils;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.NumberPicker;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";
    private NumberPicker numberPicker;
    private NumberPicker numberPicker2;
    private String[] provinces;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        //数字
        numberPicker = (NumberPicker) findViewById(R.id.numberPicker);
        numberPicker.setValue(12);
        numberPicker.setMinValue(0);
        numberPicker.setMaxValue(23);
        numberPicker.offsetTopAndBottom(5);
//        numberPicker.setEnabled(false);//不可滑动
        numberPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
            @Override
            public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
                Log.d(TAG, "oldVal=" + oldVal + ",newVal=" + newVal );
            }
        });


        //文字
        provinces = getResources().getStringArray(R.array.province);
        numberPicker2 = (NumberPicker) findViewById(R.id.numberPicker2);
        numberPicker2.setMaxValue(provinces.length - 1);
        numberPicker2.setValue(12);
        numberPicker2.setMinValue(0);
        numberPicker2.offsetTopAndBottom(5);
//        numberPicker2.setEnabled(false);//不可滑动
        numberPicker2.setDisplayedValues(provinces);
        numberPicker2.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
            @Override
            public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
                Log.d(TAG, "oldVal=" + oldVal + ",newVal=" + newVal + "," + provinces[newVal]);
            }
        });

        numberPicker.setOnScrollListener(new NumberPicker.OnScrollListener() {
            @Override
            public void onScrollStateChange(NumberPicker view, int scrollState) {
                Log.d(TAG, "scrollState=" + scrollState );
            }
        });
    }
}
